package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.interceptor.UserHolder;
import org.example.pojo.entity.ApConcern;
import org.example.mapper.ApConcernMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.service.IApConcernService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-07
 */
@Service
public class ApConcernServiceImpl extends ServiceImpl<ApConcernMapper, ApConcern> implements IApConcernService {

    @Override
    public Long

    saveConcern(int concernUserId) {
        //查询是否已经关注
        QueryWrapper<ApConcern> wrapper = new QueryWrapper<>();
        wrapper.eq("concern_user_id", concernUserId);
        wrapper.eq("user_id", UserHolder.getUserId());
        if (baseMapper.selectCount(wrapper) > 0) {
            return 1L;
        }
        ApConcern apConcern = new ApConcern();
        apConcern.setUserId(UserHolder.getUserId());
        apConcern.setConcernUserId(concernUserId);
        baseMapper.insert(apConcern);
        return 1L;

    }

    @Override
    public Long unConcern(int concernUserId) {
        //查询是否已经关注
        QueryWrapper<ApConcern> wrapper = new QueryWrapper<>();
        wrapper.eq("concern_user_id", concernUserId);
        wrapper.eq("user_id", UserHolder.getUserId());
        baseMapper.delete(wrapper);
        return 0L;
    }
}
